<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/5/30
 * Time: 13:56
 */
namespace app\admin\controller;

use app\admin\model\ComplaintModel;

class Complaint extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->complaint = new ComplaintModel();
    }
	//投诉管理列表显示
    public function index()
    {
        $list = $this->complaint->index();
		foreach($list as $key=>$val){
			$a=$list[$key]['photo'];
			$arr=array_filter(explode(',',$a));
			if($arr){
			    $list[$key]['photo']=$arr[0];
			}else{
				$list[$key]['photo']='';
			}
		}
        $page = $list->render();
        $count = count($list);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('count',$count);
        return view('complaint/index');
    }
    //投诉信息修改-》只对回复建议
    public function edit()
    {
        if(request()->isAjax())
        {
            $res = $this->complaint->edit();
			$id = request()->post('id');
            if($res)
            {
                return ['code'=>'1','message'=>'修改成功'];
            }else{
                return ['code'=>'0','message'=>'修改失败'];
            }
        }
        $id = input('id');
        $res = $this->complaint->getOneId($id);
        $arr = array_filter(explode(',',$res['photo']));
		//halt($arr);
        $this->assign('data',$res);
        $this->assign('res',$arr);
        return view('complaint/edit');
    }
	//投诉信息删除
    public function del()
    {
        $res = $this->complaint->del();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
	//投诉信息多删
    public function dell()
    {
        $res = $this->complaint->dell();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
}